<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>在线预订</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/pravate/common.css" />
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js" ></script>
		<script type="text/javascript" src="../js/config.js" ></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<style>
			#list{
				padding: 0 15px;
			}
			.list-item{
				background: #fff;
				border-radius: 5px;
				padding: 10px;
				margin-bottom: 15px;
			}
			.orderId{
				font-size: 14px;
				color: #333333;
				line-height: 14px;
				margin: 0;
				padding-bottom: 10px;
				border-bottom: 1px solid #e7e7e7;
			}
			.orderId span{
				color: #999;
				float: right;
			}
			.orderInfo{
				padding: 10px 0;
				display: flex;
			}
			.orderInfo img{
				width: 45px;
				height: 45px;
				border-radius: 22.5px;
				margin-right: 10px;
			}
			.other h5{
				font-size: 12px;
				color: #333333;
				line-height: 12px;
			}
			.time{
				margin: 0;
				margin-top: 5px;
			}
			.startTime, .endTime{
				padding: 0 20px 0 5px;
				color: #FF4400;
				font-size: 12px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title title">订单列表</h1>
		</header>
		<div class="mui-content">
		    <div id="pullrefresh">
				<ul id="list">
					<script type="text/template" id="listTemple">
						{{if status=="success"}}
							{{each data as value i}}
								<li class="list-item" data-id='{{value.order_sn}}'>
									<p class="orderId">订单号：{{value.order_sn}}<span class="span {{pay_status(value.status)}}">{{value.order_type_z}}</span></p>
									<div class="orderInfo">
										<img src="../images/qq.png" />
										<div class="other">
											<h5>房型：{{value.roomClassName}}</h5>
											<p class="time">入住
												<span class="startTime">{{value.start_time}}</span>离店
												<span class="endTime">{{value.start_time}}</span>
												<span>{{value.newDays}}晚</span>
											</p>
										</div>
									</div>
								</li>
							{{/each}}
						{{/if}}
					</script>
				</ul>
			</div>
		</div>
		<script type="text/javascript" src="../js/template-web.js"></script>
		<script>
			
			mui.plusReady(function(){
				var ws=plus.webview.currentWebview();
				$('.title').html(ws.title);
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							style: 'circle',
							callback: pulldownRefresh
						},
						up: {
							auto: true,
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				console.log(ws.status);
				var count = 1;
				var page= 1;
				var limit = 10;
				var order_type = 50;
				function pullupRefresh() {
					console.log(localStorage.getItem('token'));
					require(weburl + BookingOrderList, "json", "post", {
						token: localStorage.getItem("token"),
						page: page++, 
						limit: limit, 
						status: ws.status?ws.status:'',
						order_sn: ws.order_sn?ws.order_sn:''
					}, function(response) {
						if(response.status == "error") {
							//参数为true代表没有更多数据了。
							mui('#pullrefresh').pullRefresh().endPullup(true);
							return false; 
						}
						if(response.data.length < limit) {
							mui('#pullrefresh').pullRefresh().endPullup(true);
							upAddData(response); 
							return false;
						}
						setTimeout(function() {
							mui('#pullrefresh').pullRefresh().endPullup(false); //参数为true代表没有更多数据了。
							upAddData(response);
						}, 1500);
					}, function(xhr) {
						mui('#pullrefresh').pullRefresh().endPullup(true);
					})
				} 
				//交易状态 
				template.defaults.imports.pay_status=function(num) {
					var sta = "";
					switch(num*1) {
						case 0:
							//已取消
							sta = "text-gray";
							break;
						case 1:
							//待确认
							sta = "text-croci";
							break;
						case 2:
							//待入住
							sta = "text-bluish";
							break;
						case 3:
						    //已入住
							sta = "text-black";
							break;
						case 4:
						    //已离店
							sta = "text-gray";
							break;
					}
					return sta;
				}
				function upAddData(resData) {
					var str = template("listTemple",resData);
					$("#list").append(str);
				}
	
				function downAddData(resData) {
					//清空记录
					$("#list").html("");
					var str = template("listTemple",resData);
					$("#list").html(str);
				}
				/**
				 * 下拉刷新具体业务实现
				 */
				function pulldownRefresh() {
					page = 1;
					require(weburl + BookingOrderList, "json", "post", {
						token: localStorage.getItem("token"),
						page: page++,
						limit: limit,
						status: ws.status?ws.status:'',
						order_sn: ws.order_sn?ws.order_sn:''
					}, function(response) {
						console.log(JSON.stringify(response))
						if(response.status==='success'){
							setTimeout(function() {
								downAddData(response);
								mui('#pullrefresh').pullRefresh().endPulldown();
							}, 1500);
						}else{
							mui('#pullrefresh').pullRefresh().endPulldown();
						}
					}, function() {
						mui('#pullrefresh').pullRefresh().endPulldown();
					})
				}
				//页面跳转
				mui('body').on('tap','.pageTitle',function(){
					var title=$(this).children().html();
					console.log($(this).index())
					mui.openWindow({
						url: "reservationItem.html",
						id: "reservationItem.html",
						extras: {
							title: title+'订单列表',
							index: $(this).index()
						}
					})
				})
				//跳转到详情页
				mui('body').on('tap','.list-item',function(){
					mui.openWindow({
						url: "reserDetail.html",
						id: "reserDetail.html",
						extras: { 
							orderId: $(this).attr('data-id')
						}
					})
				})
				//跳转到房型设置页面
				mui('body').on('tap','.setting',function(){
					mui.openWindow({
						url: "roomset.html",
						id: "roomset.html"
					})
				})
			})
		</script>
	</body>

</html>